package com.whitedust.top80;

import com.whitedust.structure.TreeNode;

/**
 *
 * @author A
 * @since 2025/11/15 23:30
 */

public class Top80 {
    int res = 0;

    public int diameterOfBinaryTree(TreeNode root) {
        getHeight(root);
        return res;
    }

    private int getHeight(TreeNode root) {
        if (root == null) return 0;
        int left = getHeight(root.left);
        int right = getHeight(root.right);
        int height = Math.max(left, right) + 1;
        res = Math.max((left + right), res);
        return height;
    }
}
